<?php

class Question {

    public function __construct($question_id, $content, $marks) {
        $this->question_id = $question_id;
        $this->content = $content;
        $this->marks = $marks;
    }

}

class Page {

    public function __construct($page_id, $content, $lesson_id) {
        $this->page_id = $page_id;
        $this->content = $content;
        $this->lesson_id = $lesson_id;
    }

}

class Quiz {

    public function __construct($quiz_id) {
        $query = "select * from quizes where quiz_id='$quiz_id'";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $this->quiz_id = $quiz_id;
        $this->description = escape($row['description']);
        $this->course_id = ($row['course_id']);
        $this->pass_mark = ($row['pass_mark']);
    }

}

class Course {

    public function __construct($course_id) {
        $query = "select * from courses where id='$course_id'";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $this->id = $course_id;
        $this->course = escape($row['course']);
    }

}

class Lesson {

    public function __construct($lesson_id) {
        $query = "select * from lessons where id='$lesson_id'";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $this->lesson_id = $lesson_id;
        $this->topic = escape($row['topic']);
        $this->course_id = ($row['course']);
    }

}

class SubmittedAnswers {

    public function __construct($content, $correct_answers) {
        $this->num_of_given = 0; #number of specified correct answers
        $this->num_of_correct = 0; #how many of specified correct answers are actually correct
        $this->answers = array();
        $this->given_answers = "";

        $answerLabel = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $given_answers = "";
        for ($k = 0; $k < 4; $k++) {
            $this->answers[$answerLabel{$k}] = $content[$answerLabel{$k}];
            if ($this->answers[$answerLabel{$k}] === "true") {
                $this->num_of_given++;
                $given_answers.=$answerLabel{$k} . ",";

                if ($correct_answers[$answerLabel{$k}] == "1") {
                    $this->num_of_correct++;
                }
            }
        }
        $this->given_answers = substr($given_answers, 0, strlen($given_answers) - 1);
    }

}

class SystemAnswers {

    public function __construct($question_id) {
        $this->correct_answer_count = 0;
        $this->total_marks = 0;
        $this->answers = array();
        $this->question_id = $question_id;
        $query = "SELECT * FROM answers where question_id='$question_id' order by answers_id asc";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $answerLabel = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $count = 0;
        while ($row = mysql_fetch_assoc($result)) {
            $this->answers[$answerLabel{$count}] = $row['correct'];
            if ($row['correct'] === "1") {
                $this->correct_answer_count++;
            }
            $count++;
        }
        //what is the total marks
        $query = "SELECT * FROM questions where question_id='$question_id'";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $this->total_marks = (float) $row['marks'];
    }

}

class Results {

    public function __construct($quiz_id) {
        $this->score = 0;
        $this->total_marks = 0;
        $this->percentage = 0;
        $this->pass_mark = 0;
        $this->quiz_id = $quiz_id;
        $query = "SELECT sum(marks) as total_marks FROM questions WHERE quiz_id='$quiz_id'";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $this->total_marks = $row['total_marks'];

        $quiz = new Quiz($quiz_id);
        $this->pass_mark = $quiz->pass_mark;

        $query = "SELECT sum(marks) as score FROM user_answers WHERE question_id in (SELECT question_id FROM questions WHERE quiz_id='$quiz_id')";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $this->score = $row['score'];
        if ((float) $this->total_marks > 0) {
            $this->percentage = (int) ((float) $this->score / (float) $this->total_marks * 100);
        } else {
            $this->percentage = "0";
        }
    }

}

class BlogQuestion {

    public function __construct($blog_question_id) {
        $this->blog_question_id = $blog_question_id;
        $this->num_of_replies = numOfQuestionReplies($blog_question_id);
        $query = "SELECT * FROM blog_questions where id='$blog_question_id'";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $this->question = $row['question'];
        $this->user_id = $row['user_id'];
    }

}

class User {

    public function __construct($user_id) {
        $this->user_id = $user_id;
        $query = "SELECT * FROM students_login where id='$user_id'";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $this->username = $row['username'];
        $this->phone_number = $row['phone_number'];
    }

}

class Notification {

    public function __construct($id) {
        $query = "SELECT * FROM user_notifications where id='$id'";
        $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
        $row = mysql_fetch_assoc($result);
        $id = $row['id'];
        $this->message = escape($row['message']);
        $this->from = ($row['notif_from']);


        $query = "UPDATE user_notifications SET marked_new='1' where id='$id'";
        mysql_query($query) or die("Error executing '$query':" . mysql_error());
    }

}

function escape($str) {
    return str_replace("\n", "<br/>", str_replace(":", "\\:", str_replace("\"", "\\\"", str_replace("'", "\\'", $str))));
//    return str_replace(":", "\\:", str_replace("\"", "\\\"", str_replace("'", "\\'", $str)));
}

function phoneNoToUserID($phoneNo) {
    $query = "SELECT id FROM students_login where phone_number='$phoneNo'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    $row = mysql_fetch_array($result);
    return $row['id'];
}

function getCourse($course_id) {
    $query = "SELECT course FROM courses where id='$course_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    $row = mysql_fetch_array($result);
    $course = escape($row['course']);
    return $course;
}

function getLesson($lesson_id) {
    $query = "SELECT * FROM lessons where id='$lesson_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    $row = mysql_fetch_array($result);
    $topic = escape($row['topic']);
    return $topic;
}

function getQuiz($quiz_id) {
    $quiz = new Quiz($quiz_id);
    return $quiz->description;
}

function getQuestion($quiz_id, $user_id) {
    $query = "SELECT * FROM questions WHERE quiz_id='$quiz_id' AND
    question_id NOT IN (SELECT question_id FROM user_answers WHERE user_id='$user_id')
    ORDER BY question_id ASC LIMIT 0,1";
//    echo $query;
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        return FALSE;
    } else {
        $row = mysql_fetch_assoc($result);
        $content = escape($row['content']);
        $question_id = escape($row['question_id']);
        $marks = $row['marks'];
        return new Question($question_id, $content, $marks);
    }
}

function prepareMobileQuestion($quiz_id, $user_id, $message=FALSE) {
    $title = getQuiz($quiz_id);
    $question = getQuestion($quiz_id, $user_id);
    $finalStr = "";
    if ($question) {
        $answers = getAnswers($question->question_id);
        $finalStr.="{form:{title:'$title Question X', form_id:'question$quiz_id" . Sympols::$split5 . "$question->question_id" . "', items:[";
        if ($message) {
            $finalStr.="{message:{text:'$message'}}, ";
        }
        $finalStr.="{label:{text:'<i>$question->content ($question->marks marks)</i>'}}, ";
        $finalStr.="$answers";
        $finalStr.="]}}";
    } else {
        $finalStr.="{form:{title:'$title Quiz Done!', form_id:'quizDone$quiz_id', items:[";
        $finalStr.="{label:{text:'You have done all the questions!'}},";
        $finalStr.="{checkbox:{id:'viewResults', label:'View Results'}}";
        $finalStr.="]}}";
    }
    return $finalStr;
}

function getAnswers($question_id) {
    $query = "SELECT * FROM answers where question_id='$question_id' order by answers_id asc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    $answerLabel = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $count = 0;
    $ansStr = "";
    while ($row = mysql_fetch_assoc($result)) {
        $answer = escape($row['answer']);
        $ansStr.="{checkbox:{id:'" . $answerLabel{$count} . "', label:'" . $answerLabel{$count} . ". $answer'}}, ";
        $count++;
    }
    return substr($ansStr, 0, strlen($ansStr) - 1);
}

function getCourses($query=NULL, $courses_done="all") {
    $coursesStr = "";
    if (!$query) {
        $query = "SELECT * FROM courses order by course asc";
    }
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $coursesStr.="{id:'noCourses', label:'No courses are available'}";
    } else {
        $cs = "";
        $count = 1;
        while ($row = mysql_fetch_assoc($result)) {
            $id = $row['id'];
            $course = escape($row['course']);
            if ($courses_done == "all") {//used by blogging
                $done = courseDone($id, phoneNoToUserID($_GET['phone_number'])) ? "(Read!)" : "";
                $cs.= "{id:'$id', label:'$count. $course $done'},";
            } else if ($courses_done == "true") {//used by quizes
                if (courseDone($id, phoneNoToUserID($_GET['phone_number']))) {
                    $cs.= "{id:'$id', label:'$count. $course'},";
                }
            } else if ($courses_done == "false") {//used by courses and downloads
              //  if (!courseQuizesDone($id)) {
                    $done = courseDone($id, phoneNoToUserID($_GET['phone_number'])) ? "(Read)" : "";
                    $cs.= "{id:'$id', label:'$count. $course $done'},";
              //  }
            }
            $count++;
        }
        if (strlen($cs) > 0) {
            $cs = substr($cs, 0, strlen($cs) - 1);
            $coursesStr.=$cs;
        } else {
            $coursesStr.="{id:'noCourses', label:'No courses are available for you.'}";
        }
    }
    return $coursesStr;
}

function getBlogQuestions($course_id) {
    $quesStr = "";
    $query = "SELECT * FROM blog_questions where course_id='$course_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $quesStr.="{id:'noQuestions', label:'No questions yet under this course'}";
    } else {
        while ($row = mysql_fetch_assoc($result)) {
            $id = $row['id'];
            $question = escape($row['question']);
            $maxlen = 15;
            if (strlen($question) > $maxlen) {
                $question = substr($question, 0, $maxlen) . "...";
            }
            $replies = numOfQuestionReplies($id);
            $quesStr.= "{id:'$id', label:'$question ($replies replies)'},";
        }
        $quesStr = substr($quesStr, 0, strlen($quesStr) - 1);
    }
    return $quesStr;
}

function getBlogReplies($blog_question_id) {
    $quesStr = "";
    $query = "SELECT * FROM blog_replies where blog_question_id='$blog_question_id' order by date_sent desc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $quesStr.="{label:{text:'No comments have been added yet'}}";
    } else {
        while ($row = mysql_fetch_assoc($result)) {
            $id = $row['id'];
            $reply = escape($row['reply']);
            $user = new User($row['user_id']);
            $quesStr.= "{label:{text:'$user->username: $reply'}},";
        }
        $quesStr = substr($quesStr, 0, strlen($quesStr) - 1);
    }
    return $quesStr;
}

function getUserNotifications() {
    $quesStr = "";
    $user_id = phoneNoToUserID($_GET['phone_number']);
    $query = "SELECT * FROM user_notifications where user_id='$user_id' and marked_read='0' order by date_sent desc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $quesStr.="{id:'noneNotifs',label:'No new notifications'}";
    } else {
        while ($row = mysql_fetch_assoc($result)) {
            $id = $row['id'];
            $message = escape($row['message']);
            $from = ($row['notif_from']);

            $maxlen = 12;
            if (strlen($message) > $maxlen) {
                $message = substr($message, 0, $maxlen) . "...";
            }
            $new = $row['marked_new'];
            $open_tag = $new == 0 ? "<b>" : "";
            $close_tag = $new == 0 ? "</b>" : "";
            $quesStr.= "{id:'$id',label:'$open_tag$from: $message$close_tag'},";
        }
        $quesStr = substr($quesStr, 0, strlen($quesStr) - 1);
    }
    return $quesStr;
}

function numOfNewNotifs() {
    $user_id = phoneNoToUserID($_GET['phone_number']);
    $query = "SELECT count(*) as num FROM user_notifications WHERE user_id='$user_id' and marked_new = '0'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    $row = mysql_fetch_assoc($result);
    return $row['num'];
}

function numOfQuestionReplies($blog_question_id) {
    $query = "SELECT count(*) as num FROM blog_replies WHERE blog_question_id = '$blog_question_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    $row = mysql_fetch_assoc($result);
    return $row['num'];
}

function getEnrolledCourses($user_id, $enrolled=TRUE, $course_done="all") {//FETCH ENNROLLED OR NOT-ENROLLED COURSES
    $coursesStr = "";
    $enrolled_query = "SELECT course_id FROM enrollment WHERE user_id = '$user_id'";
    $query = "SELECT * FROM courses WHERE id " . ($enrolled ? "IN" : "NOT IN") . " ($enrolled_query) order by course asc";
    return getCourses($query, $course_done);
}

function markNotifRead($notif_id) {
    $query = "UPDATE user_notifications SET marked_read='1' WHERE id='$notif_id'";
    mysql_query($query) or die("Error executing '$query':" . mysql_error());
}

function acceptCondtion() {
    $user_id = phoneNoToUserID($_GET['phone_number']);
    $query = "INSERT INTO user_condition SET user_id='$user_id'";
    mysql_query($query) or die("Error executing '$query':" . mysql_error());
}

function hasAcceptCondtion() {
    $user_id = phoneNoToUserID($_GET['phone_number']);
    $query = "SELECT * FROM user_condition WHERE user_id='$user_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    return mysql_num_rows($result) > 0;
}

function enrollCourse($user_id, $course_id) {//FETCH ENNROLLED OR NOT-ENROLLED COURSES
    $coursesStr = "";
    $query = "INSERT INTO enrollment SET course_id='$course_id',user_id = '$user_id'";
    if (mysql_query($query)) {
        addNotification("You have successfully enrolled in -" . getCourse($course_id) . "-, Go Home>Courses to access contents", "System");
        return "You have successfully enrolled in -" . getCourse($course_id) . "-, Go Home>Courses to access contents";
    } else {
        return "Enrollment failed, please try again later";
    }
}

function getLessons($course_id, $user_id) {
    $lessonsStr = "";
    $query = "SELECT * FROM lessons where course='$course_id' order by 'date_added' desc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $lessonsStr.="{id:'noLesson', label:'No Lessons are available for this course'}";
    } else {
        $cs = "";
        while ($row = mysql_fetch_assoc($result)) {
            $id = $row['id'];
            $topic = escape($row['topic']);
            $done = lessonDone($id, $user_id) ? "(Read)" : "";
            $cs.= "{id:'$id', label:'$topic $done'},";
        }
        $cs = substr($cs, 0, strlen($cs) - 1);
        $lessonsStr.=$cs;
    }
    return $lessonsStr;
}

function getLessonPage($lesson_id, $offset, $user_id) {
    $query = "SELECT * FROM lesson_pages where lesson_id='$lesson_id' limit $offset, 1";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) > 0) {
        $row = mysql_fetch_assoc($result);
        $page_id = ($row['id']);
        $content = escape($row['content']);
        $lesson_id = ($row['lesson_id']);
        return new Page($page_id, $content, $lesson_id);
    } else {
        recordLessons($user_id, $lesson_id);
        $lesson = new Lesson($lesson_id);
        if (courseDone($lesson->course_id, $user_id)) {
            $course = new Course($lesson->course_id);
            addNotification("You have completed the course $course->course, the quiz is now available.", "System");
        }
        return FALSE;
    }
}

function lessonDone($lesson_id, $user_id) {
    $query = "SELECT * FROM user_lessons where user_id='$user_id' AND lesson_id='$lesson_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    return mysql_num_rows($result) > 0;
}

function courseDone($course_id, $user_id) {
    $query = "SELECT * FROM lessons where course='$course_id' order by 'date_added' desc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    $num_lessons = mysql_num_rows($result);
    $query = "SELECT * FROM user_lessons where user_id='$user_id' AND lesson_id in (SELECT id FROM lessons where course='$course_id')";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    $num_done = mysql_num_rows($result);
    return $num_done == $num_lessons;
}

function recordLessons($user_id, $lesson_id) {
    $query = "DELETE FROM user_lessons WHERE user_id='$user_id' AND lesson_id='$lesson_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());

    $query = "INSERT INTO user_lessons SET user_id='$user_id', lesson_id='$lesson_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
}

function getQuizList($course_id, $user_id) {
    $quizList = "";
    $query = "SELECT * FROM quizes where course_id='$course_id' order by date_added desc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $quizList.="{id:'noQuiz', label:'This course does not have quizes'}";
    } else {
        $cs = "";
        while ($row = mysql_fetch_assoc($result)) {
            extract($row);
            $done = getQuestion($quiz_id, $user_id) ? "" : " (Done!)";
//            var_dump($done);
            $cs.= "{id:'$quiz_id', label:'$description $done'}, ";
        }
        $cs = substr($cs, 0, strlen($cs) - 1);
        $quizList.=$cs;
    }
    return $quizList;
}

function courseQuizesDone($course_id) {
    $query = "SELECT * FROM quizes where course_id='$course_id' order by date_added desc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        return FALSE;
    } else {
        $user_id = phoneNoToUserID($_GET['phone_number']);
        while ($row = mysql_fetch_assoc($result)) {
            extract($row);
            if (getQuestion($quiz_id, $user_id)) {//if any of the quizes still has questions, then the course is not done
                return FALSE;
            }
        }
        return TRUE;
    }
}

function recordAnswers($user_id, $system_answers, $given_answers) {
    $user_marks = $given_answers->num_of_correct / $system_answers->correct_answer_count * $system_answers->total_marks;
//    var_dump($user_marks);
    $query = "INSERT INTO user_answers SET user_id='$user_id', question_id='$system_answers->question_id', 
            marks='$user_marks',max_marks='$system_answers->total_marks', answers='$given_answers->given_answers'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
}

function deleteAnswers($quiz_id) {
    $user_id = phoneNoToUserID($_GET['phone_number']);
    $query = "DELETE FROM user_answers WHERE user_id='$user_id' and question_id in (SELECT question_id FROM questions WHERE quiz_id='$quiz_id')";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());

    $quiz = new Quiz($quiz_id);
    $query = "DELETE FROM user_lessons WHERE user_id='$user_id' and lesson_id in (SELECT id FROM lessons WHERE course='$quiz->course_id')";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
}

function addNotification($message, $from, $user_id=NULL) {
    if (!$user_id) {
        $user_id = phoneNoToUserID($_GET['phone_number']);
    }
    $query = "INSERT INTO user_notifications SET user_id='$user_id', message='$message',
            notif_from='$from'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
}

function addBlogQuestion($course_id, $question) {
    $user_id = phoneNoToUserID($_GET['phone_number']);
    $query = "INSERT INTO blog_questions SET user_id='$user_id', course_id='$course_id',
            question='$question'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
}

function addBlogReply($blog_question_id, $reply) {
    $user_id = phoneNoToUserID($_GET['phone_number']);
    $blogQuest = new BlogQuestion($blog_question_id);
    $maxlength = 10;
    if (strlen($blogQuest->question) > $maxlength) {
        $blogQuest->question = substr($blogQuest->question, 0, $maxlength);
    }
    $user = new User($user_id);
    addNotification("A reply has been added to your blog question -" . $blogQuest->question . "- by user $user->username ", "System", $blogQuest->user_id);
    $query = "INSERT INTO blog_replies SET user_id='$user_id', blog_question_id='$blog_question_id',
            reply='$reply'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
}

function downloadEnrolledCourses($user_id) {//only enrolled courses which are not done yet
    $coursesStr = "";
    $enrolled_query = "SELECT course_id FROM enrollment WHERE user_id = '$user_id'";
    $query = "SELECT * FROM courses WHERE id IN ($enrolled_query) order by course asc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $coursesStr.="0";
    } else {
        $cs = "";
        while ($row = mysql_fetch_assoc($result)) {
            $id = $row['id'];
            if (!courseQuizesDone($id)) {
                $course = escape($row['course']);
                $cs.= "$id" . Sympols::$split2 . "$course" . Sympols::$split1;
            }
        }
        if (strlen($cs) > 0) {
            $cs = substr($cs, 0, strlen($cs) - strlen(Sympols::$split1));
            $coursesStr.=$cs;
        } else {
            $coursesStr.="0";
        }
    }
    return $coursesStr;
}

function downloadLessons($course_id) {
    $lessonsStr = "";
    $query = "SELECT * FROM lessons WHERE course = '$course_id' order by 'date_added' desc";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $lessonsStr.="0";
    } else {
        $cs = "";
        while ($row = mysql_fetch_assoc($result)) {
            $id = $row['id'];
            $topic = escape($row['topic']);
            $course_id = $row['course'];
            $cs.= "$id" . Sympols::$split2 . "$topic" . Sympols::$split2 . "$course_id" . Sympols::$split1;
        }
        $cs = substr($cs, 0, strlen($cs) - strlen(Sympols::$split1));
        $lessonsStr.=$cs;
    }
    return $lessonsStr;
}

function downloadpages($lesson_id) {
    $contentStr = "";
    $query = "SELECT * FROM lesson_pages where lesson_id='$lesson_id'";
    $result = mysql_query($query) or die("Error executing '$query':" . mysql_error());
    if (mysql_num_rows($result) == 0) {
        $contentStr.="0";
    } else {
        while ($row = mysql_fetch_assoc($result)) {
            $id = ($row['id']);
            $content = escape($row['content']);
            $less_id = ($row['lesson_id']);
            $contentStr.="$id" . Sympols::$split2 . "$content" . Sympols::$split2 . "$less_id" . Sympols::$split1;
        }
        $contentStr = substr($contentStr, 0, strlen($contentStr) - strlen(Sympols::$split1));
    }
    return $contentStr;
}